package com.lzc.syn;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 用Lock的形式表现
 *
 * @author lizhichuan
 * @date 2024/7/11 11:03
 */
public class SynchronizedToLock12 {

    Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        SynchronizedToLock12 s = new SynchronizedToLock12();
        s.method1();
        s.method2();
    }

    private synchronized void method1() {
        System.out.println("我是synchronized形式");
    }

    private void method2() {
        lock.lock();
        try {
            System.out.println("我是Lock形式");
        }finally {
            lock.unlock();
        }

    }
}
